import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Solution684 {
    public int[] findRedundantConnection(int[][] edges) {
        Map<Integer,Integer> map=new HashMap<>();
        for (int[] edge : edges) {
            if (!map.containsKey(edge[0])){
                map.put(edge[0],edge[0]);
            }
            if (!map.containsKey(edge[1])){
                map.put(edge[1],edge[1]);
            }
            int x=find(map,edge[0]);
            int y=find(map,edge[1]);
            if (x!=y){
                map.put(x,y);
            }else{
                return edge;
            }
        }
        return null;
    }

    int find(Map<Integer,Integer> map,int t){
        while (t!=map.get(t)){
            t=map.get(t);
        }
        return t;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution684().findRedundantConnection(new int[][]{{1,2},{1,3},{2,3}})));
    }
}
